/*
 * ButtonsRowOption.java
 * Copyright (C) 2007 Ezequiel Turovetzky
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
package ar.com.botonera.gui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBoxMenuItem;

import ar.com.botonera.Application;
import ar.com.botonera.Botonera;

/**
 * Item que representa una opci&oacute;n que puede ser elegida
 * para establecer la cantidad de botones que se ver&aacute;n por fila
 * en la botonera.
 * <br>
 * El submen&uacute; <code>ButtonRowsSubmenu</code> se compone de
 * instancias de esta clase.
 * <br>
 * S&oacute;lo una opci&oacute;n puede ser elegida.
 * @author <a href="mailto:tezequiel@gmail.com">Ezequiel Turovetzky</a>
 * @version 1.0
 */
public class ButtonsRowOption extends JCheckBoxMenuItem implements ActionListener {

    //~ Instance fields --------------------------------------------------------

    /** Texto y valor de este item */
    private int value;

    //~ Constructors -----------------------------------------------------------

    /**
     * Creates a new ButtonsRowOption object.
     * @param value Valor de este &iacute;m. Es el texto que visualizar&aacute;. 
     */
    public ButtonsRowOption(int value) {
        if(value > 0) {
            this.value = value;
            setText(String.valueOf(value));
            addActionListener(this);
        } else {
            throw new IllegalArgumentException("Debe ser mayor que cero. El valor ingresado es invalido: " + value);
        }
    }

    //~ Methods ----------------------------------------------------------------

    /**
     * Establece en la botonera la nueva cantidad de botones por fila.
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        Botonera botonera = Application.getInstance().getWindow().getBotonera();
        botonera.setButtonsPerRow(value);
    }
}
